import type { ButtonProps } from 'naive-ui'
import type { FcBtnProps } from '@/types/fcform/unit'
import { NButton } from 'naive-ui'

const createBtn = (text: string, props: ButtonProps = {}) => {
  return h(
    NButton,
    {
      size: 'small',
      quaternary: true,
      ...props,
    },
    { default: () => text },
  )
}

const FcBtn = (props: FcBtnProps) => {
  const { type = 'primary', defaultIcon = 'esayIcon-tianjiawenjianjia', icon = true, text } = props
  const children = []
  if (icon) {
    const iconName = typeof icon === 'string' ? icon : defaultIcon
    children.push(h('i', { class: `esayIcon ${iconName}` }))
  }
  if (text) {
    const style = icon ? { marginLeft: '5px' } : {}
    children.push(h('span', { style }, text))
  }
  return h(NButton, { type }, () => children)
}
const fastUnit = {
  createBtn,
  FcBtn,
}
export default fastUnit
